import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
testCase="DBshop003_余额支付流程"
# 1.在首页搜索"小米",点击搜索按钮
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_xpath("//input[@name='keywords']").send_keys("小米")
firefox.find_element_by_xpath("//input[@class='search-btn iconfont']").click()
# 2.选择小米mix3,加入到购物车,点击购物车按钮
firefox.find_element_by_xpath("//img[@alt='小米Mix3 全网通版 8GB+128GB 黑色 磁动力滑盖全面屏']").click()
switchWindow(firefox,2)
firefox.find_element_by_id("add_cart_submit").click()
firefox.find_element_by_link_text("去购物车结算").click()
# 3.点击"去结算"按钮
firefox.find_element_by_link_text("去结算").click()
# 4.默认地址已经别选择,点击下一步按钮
firefox.find_element_by_xpath("//input[@value='下一步']").click()
# 5.支付方式选择"货到付款",点击确认订单。
firefox.find_element_by_xpath("//input[@value='hdfk']").click()
firefox.find_element_by_xpath("//input[@value='确认订单']").click()
# 记录订单编号
orderNumber=firefox.find_element_by_xpath("(//font[@color='color:#ED145B'])[2]").text
rootpath=get_pro_rootpath()
writeFile(rootpath+'\public\order2.txt',orderNumber)
firefox.quit()
# 6.登录后台管理系统,地址是"http://localhost/dbshop/admin",
firefox=openBrowser("http://localhost/dbshop/admin")
DBshopLoginAdmin(firefox)
# 7.点击销售管理订单管理，找到刚才前台提交的订单，点击“编辑查看”。
DBshopEnterMenu2(firefox,"销售管理","订单管理")
firefox.find_element_by_xpath("(//input[@name='order_sn'])[1]").send_keys(orderNumber)
firefox.find_element_by_xpath("(//button[@class='btn btn-small btn-primary'])[1]").click()
firefox.find_element_by_link_text("编辑查看").click()
# 8.点击发货操作按钮，编辑快递单号“1000000000” 发货说明“保证正品”，点击“点击发货”按钮。
firefox.find_element_by_link_text("发货操作").click()
firefox.find_element_by_id("express_number").send_keys("1000000000")
firefox.find_element_by_id("state_info").send_keys("保证正品")
firefox.find_element_by_xpath("//button").click()
time.sleep(2)
# 9.点击付款操作按钮,付款状态选择"已付款",点击提交保存按钮
firefox.find_element_by_link_text("付款操作").click()
firefox.find_element_by_xpath("(//option)[3]").click()
firefox.find_element_by_xpath("//button").click()
firefox.quit()
# 10.进入dbshop前台我的订单—已发货，点击“确认收货”按钮，完成订单。
firefox=openBrowser("http://localhost/dbshop")
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_partial_link_text("已发货").click()
firefox.find_element_by_xpath("//input[@name='search_order_sn']").send_keys(orderNumber)
firefox.find_element_by_xpath("//button[text()='搜索']").click()
firefox.find_element_by_xpath("//button[text()='确认收货']").click()
firefox.find_element_by_xpath("//button").click()
time.sleep(1)
firefox.switch_to.alert.accept()
# 11.进入dbshop前台查看我的订单"交易完成"中,检查上面的订单状态
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_partial_link_text("交易完成").click()
try:
    if firefox.find_element_by_link_text(orderNumber).is_displayed():
        writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
